package com.farmer.consultation.controller;

import com.farmer.common.entity.ConsultationQa;
import com.farmer.common.result.Result;
import com.farmer.consultation.service.ConsultationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 咨询问答控制器
 */
@Slf4j
@RestController
@RequestMapping("/consultation")
public class ConsultationController {

    @Autowired
    private ConsultationService consultationService;

    @GetMapping("/list")
    public Result<?> getConsultationList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String category,
            @RequestParam(required = false) String questionStatus,
            @RequestParam(required = false) Integer isPublic,
            @RequestParam(required = false) String keyword) {
        return consultationService.getConsultationList(pageNum, pageSize, category, questionStatus, isPublic, keyword);
    }

    @GetMapping("/{consultationId}")
    public Result<?> getConsultationById(@PathVariable Long consultationId) {
        return consultationService.getConsultationById(consultationId);
    }

    @PostMapping("/question")
    public Result<?> submitQuestion(@RequestBody ConsultationQa consultation) {
        return consultationService.submitQuestion(consultation);
    }

    @PutMapping("/{consultationId}/answer")
    public Result<?> answerQuestion(
            @PathVariable Long consultationId,
            @RequestParam String answerContent,
            @RequestParam(required = false) String answerImages) {
        return consultationService.answerQuestion(consultationId, answerContent, answerImages);
    }

    @GetMapping("/statistics")
    public Result<?> getConsultationStatistics() {
        return consultationService.getConsultationStatistics();
    }
} 